#ifndef __MEM_DEBUG_H__
#define __MEM_DEBUG_H__

#ifdef _TRACK_MEM_USAGE

#include <stdio.h>

void DebugFree(void *p);
void *DebugMalloc(size_t size, const char *file, int line);
void *DebugCalloc(size_t nmemb, size_t size, const char *file, int line);

void *operator new(size_t size, const char *file, int line);
void operator delete(void *p);
void operator delete[](void *p);

void ReportMemLeaks(FILE *stream=stderr);

#define free(xxx) DebugFree(xxx)
#define malloc(xxx) DebugMalloc(xxx, __FILE__, __LINE__)
#define calloc(xxx, yyy) DebugCalloc(xxx, yyy, __FILE__, __LINE__)

#define new new(__FILE__, __LINE__)
#define REPORT_MEM_LEAKS ReportMemLeaks

#else

#define REPORT_MEM_LEAKS NULL

#endif

#endif
